var groupArray = require('group-array');
var mirr = require("mirrarray");
 


/**
 * 是否是有效key 不能包含复杂数据类型
 * @param  {[type]}  element [description]
 * @return {Boolean}         [description]
 */
function isValidKey (element){ 
	const isNull = element === null 
	return ['string', 'number', 'boolean', 'undefined'].includes(typeof element) || isNull
}

/**
 * 没有转换字符串后相同的key,
 * @param  {[type]} element  [description]
 * @param  {Object} keysSeen [description]
 * @return {[type]}          [description]
 */
function nonOverlappingKey(element, keysSeen = {}) {
	const isNull = element === null 
	const thisType = isNull ? 'null' : typeof element
	const typeSeenBefore = keysSeen['' + element]

	if(typeSeenBefore) {
		return thisType === typeSeenBefore
	} else {
		keysSeen['' + element] = thisType
		return true
	}
}



function mirrArray(arr) {

	const keysSeen = {}
	return arr.reduce((acc, key) => {
		if(!isValidKey(key)) {
			throw new TypeError(' in valid key')
		}
		if(!nonOverlappingKey(key, keysSeen)){
			throw new TypeError(' OverlappingKey')
		}
		acc[key] = key
		return acc
	}, {})
}


var env = typeof window === 'object' && this === window ? 'BROWSER' : 'NODE';

if(env === 'NODE') {
	// 导出一个函数
	module.exports = mirrArray
} 

